
import {
  getSex,
  getNat,
  getCitType,
  getSchrec,
  getPosgr,
  getAgencyPeride,
  getFundmode,
  getGr,
  getTecgr,
  getSalagr,
  getAgencyBank,
  getSalaryType,
  getCountry,
  getFirstAuthAgencyData,
  getAuthAgencyTree
} from '@/api/baseInfo'
import { querySalPostByPersonTypeId, querySalPersonTypeAll, querySalPostGradeLevelAll } from '@/api/salaryConfigManage/personTypePostConfig'
import { getAllAgency } from '@/api/unitInformationMaintenance/unitInformationEdit'

const state = {
  sexLists: [],
  natLists: [], // 民族
  citTypeLists: [], // 证件类型代码
  schrecLists: [], // 学历
  posgrLists: [], // 职务
  grLists: [], // 职级
  tecgrLists: [], // 技术等级
  salagrLists: [], // 工资级别
  agencyBankLists: [], // 银行
  countryLists: [], // 国籍
  personPerideLists: [], // 人员身份
  fundmodeLists: [], // 人员经费保障方式
  agencyLists: [], // 单位信息集合
  meritPayCodeList:[],//工资类型
  salaryTypes: [], // 人员类型
  personTypeList: [],//标准工资人员类型
  postList: [],//标准工资职务
  gradeList: [],//标准工资档次
  levelList: [],//标准工资级别 
  getFirstAuthAgencyData: '',
  agencyTreeData: [],   
}

const mutations = {
  SET_SEXLISTS:(state,sexLists)=>{// 性别
    state.sexLists = sexLists
  },
  SET_NATLISTS:(state,natLists)=>{
    state.natLists = natLists
  },
  SET_CITTYPELISTS:(state,citTypeLists)=>{
    state.citTypeLists = citTypeLists
  },
  SET_SCHRECLISTS:(state,schrecLists)=>{
    state.schrecLists = schrecLists
  },
  SET_POSGRLISTS:(state,posgrLists)=>{
    state.posgrLists = posgrLists
  },
  SET_GRLISTS:(state,grLists)=>{
    state.grLists = grLists
  },
  SET_TECGRLISTS:(state,tecgrLists)=>{
    state.tecgrLists = tecgrLists
  },
  SET_SALAGRLISTS:(state,salagrLists)=>{
    state.salagrLists = salagrLists
  },
  SET_AGENCYBANKLISTS:(state,agencyBankLists)=>{
    state.agencyBankLists = agencyBankLists
  },
  SET_COUNTRYLISTS:(state,countryLists)=>{
    state.countryLists = countryLists
  },
  SET_PERSONPERIDELISTS:(state,personPerideLists)=>{
    state.personPerideLists = personPerideLists
  },
  SET_FUNDMODELISTS:(state,fundmodeLists)=>{
    state.fundmodeLists = fundmodeLists
  },
  SET_AGENCYLISTS:(state,agencyLists)=>{
    state.agencyLists = agencyLists
  },
  SET_MERITPAYCODELIST:(state,meritPayCodeList)=>{
    state.meritPayCodeList = meritPayCodeList
  },
  SET_SALARYTYPES:(state,salaryTypes)=>{
    state.salaryTypes = salaryTypes
  },
  SET_PERSONTYPELIST:(state,personTypeList)=>{
    state.personTypeList = personTypeList
  },
  SET_POSTLIST:(state,postList)=>{
    state.postList = postList
  },
  SET_GRADELIST:(state,gradeList)=>{
    state.gradeList = gradeList
  },
  SET_LEVELLIST:(state,levelList)=>{
    state.levelList = levelList
  },
  SET_GETFIRSTAUTHAGENCYDATA:(state,getFirstAuthAgencyData)=>{
    state.getFirstAuthAgencyData = getFirstAuthAgencyData
  },
  SET_AGENCYTREEDATA:(state,agencyTreeData)=>{
    state.agencyTreeData = agencyTreeData
  }
}

const actions = {
  getBaseData({ commit }){
    getSex().then(response => {
        commit('SET_SEXLISTS', Object.assign({}, response.data))
      })
      getNat().then(response => {
        commit('SET_NATLISTS', Object.assign({}, response.data))
      })
      getCitType().then(response => {
        commit('SET_CITTYPELISTS', Object.assign({}, response.data))
      })
      getSchrec().then(response => {
        commit('SET_SCHRECLISTS', Object.assign({}, response.data))
      })
      getPosgr().then(response => {
        commit('SET_POSGRLISTS', Object.assign({}, response.data))
      })
      getGr().then(response => {
        commit('SET_GRLISTS', Object.assign({}, response.data))
      })
      getTecgr().then(response => {
        commit('SET_TECGRLISTS', Object.assign({}, response.data))
      })
      getSalagr().then(response => {
        commit('SET_SALAGRLISTS', Object.assign({}, response.data))
      })
      getAgencyBank().then(response => {
        commit('SET_AGENCYBANKLISTS', Object.assign({}, response.data))
      })
      getCountry().then(response => {
        commit('SET_COUNTRYLISTS', Object.assign({}, response.data))
      })
      getAgencyPeride().then(response => {
        commit('SET_PERSONPERIDELISTS', Object.assign({}, response.data))
      })
      getFundmode().then(response => {
        commit('SET_FUNDMODELISTS', Object.assign({}, response.data))
      })
      getAllAgency().then(response => {
        commit('SET_AGENCYLISTS', Object.assign({}, response.data))
      })
      getSalaryType().then(response => {
        commit('SET_MERITPAYCODELIST', Object.assign({}, response.data))
      })
      querySalPersonTypeAll().then((response) => {
        commit('SET_PERSONTYPELIST', Object.assign({}, response.data))
      })
      getPosgr().then(response => {
        commit('SET_POSGRLISTS', Object.assign({}, response.data))
      })
      getGr().then(response => {
        commit('SET_GRLISTS', Object.assign({}, response.data))
      })
      const params = { 'personTypeId': '' }
      querySalPostByPersonTypeId(params).then((response) => {
        commit('SET_POSTLIST', Object.assign({}, response.data))
      })
      const params2 = { 'personTypeId': '', 'postId': '', type: 'grade' }
      querySalPostGradeLevelAll(params2).then((response) => {
        commit('SET_GRADELIST', Object.assign({}, response.data))
      })
      const params1 = { 'personTypeId':'', 'postId': '', type: 'level' }
      querySalPostGradeLevelAll(params1).then((response) => {
        this.levelList = Object.assign(response.data)
        commit('SET_LEVELLIST', Object.assign({}, response.data))
      })
      getFirstAuthAgencyData().then(response => {
        commit('SET_GETFIRSTAUTHAGENCYDATA',  response.data)
      })
      getAuthAgencyTree().then(response => {
        commit('SET_AGENCYTREEDATA',  response.data)
      })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
